<template>
    <el-card shadow="hover">
        <el-form :inline="true">
            <el-form-item label="一级分类">
                <el-select :disabled="scene === 0 ? false : true" placeholder="请您选择一级分类" style="width: 240px;" v-model="categoryStore.c1Id" @change="getC2">
                    <el-option v-for="c1 in categoryStore.c1Arr" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="二级分类">
                <el-select :disabled="scene === 0 ? false : true" placeholder="请您选择二级分类" style="width: 240px;" v-model="categoryStore.c2Id" @change="getC3">
                    <el-option v-for="c2 in categoryStore.c2Arr" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="三级分类">
                <el-select :disabled="scene === 0 ? false : true" placeholder="请您选择三级分类" style="width: 240px;" v-model="categoryStore.c3Id">
                    <el-option v-for="c3 in categoryStore.c3Arr" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script setup lang="ts">
import { onMounted,onUnmounted } from 'vue';
import useCategoryStore from '@/stores/category'
// 获取分类仓库
const categoryStore = useCategoryStore();
onMounted(()=>{
    getC1();
})
const getC1 = ()=>{
    categoryStore.getC1();
}
const getC2 = ()=>{
    categoryStore.c2Id = '';
    categoryStore.c3Arr = [];
    categoryStore.c3Id = '';
    categoryStore.getC2();
}
const getC3 = ()=>{
    categoryStore.c3Id = '';
    categoryStore.getC3();
}
//分类全局组件销毁钩子
onUnmounted(() => {
    //重置仓库的数据
    //$reset方法只有选择是API仓库才可以使用,组合式API仓库使用不了!!!
    categoryStore.$reset();
})
defineProps(["scene"]);

</script>








<script lang="ts">
export default {
    name: 'Category'
}
</script>
<style scoped></style>


